package demo.um.interceptor;

import java.util.logging.Logger;

import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

import demo.um.controller.EventController;

@Interceptor
@ParameterLogger
public class ParameterLoggerInterceptor {

	@Inject
	private Logger logger;

	@Inject
	private EventController eventController;

	@AroundInvoke
	public Object aroundInvoke(InvocationContext ic) throws Exception {
		String log = "Logging parameter value for parameter of method: " + ic.getMethod().getName() + "(" + ic.getParameters()[0] + ")";
		logger.info(log);
		eventController.setLog(log);
		return ic.proceed();
	}

}
